package com.gitee.lirenqing.flinksimpledatakafkasink;

import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class SimpleSource implements SourceFunction<String> {

    private boolean running = true;

    @Override
    public void run(SourceContext<String> sourceContext) throws Exception {
        List<String> books = new ArrayList<>();
        books.add("Pyhton从入门到放弃");
        books.add("Java从入门到放弃");
        books.add("Php从入门到放弃");
        books.add("C++从入门到放弃");
        books.add("Scala从入门到放弃");
        books.add("颈椎病康复指南");
        while (running) {
            int i = new Random().nextInt(6);
            sourceContext.collect(books.get(i));
            Thread.sleep(2000);
        }
    }

    @Override
    public void cancel() {
        running = false;
    }
}
